﻿Imports BLL
Imports DAL
Public Class SubCategoriaCAD
    Inherits System.Web.UI.Page
    Dim objbll As New SubCategoriaBLL
    Dim cod As Integer = 0
#Region "Eventos"
#Region "Botão Gravar"
    Protected Sub BGravar_Click(sender As Object, e As EventArgs) Handles BGravar.Click
        Try
            objbll = New SubCategoriaBLL(Val(TCodigo.Text), TDescricao.Text.Trim, DDLCategoria.SelectedValue)
            If (objbll.InserirAlterar(Session("usu_nome"))) Then
                BGravar.Enabled = False
                LMSG.Text = "Gravado com Sucesso!"
                LMSG.Visible = True
            End If
        Catch ex As Exception
            LMSG.ForeColor = Drawing.Color.Red
            LMSG.Text = ex.Message
            LMSG.Visible = True
        End Try
    End Sub
#End Region

#Region "Load"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objconexao As New Conexao

        cod = 0
        If (Not IsPostBack()) Then
            objconexao.preencheCombo(DDLCategoria, "Mul_Categoria", "cat_codigo", "cat_descricao", "", "cat_descricao")
            If Not IsNothing(Request("id")) Then
                cod = Val(Request("id"))
                BGravar.Text = "Alterar"
                carrega()
            End If
        End If
    End Sub
#End Region
#End Region

#Region "Métodos"
    Public Sub carrega()
        objbll = New SubCategoriaBLL(Val(cod))
        TCodigo.Text = objbll.Codigo
        TDescricao.Text = objbll.Descricao
        DDLCategoria.SelectedValue = objbll.CatCodigo
    End Sub
#End Region

    Protected Sub ImageButton1_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim obj As New Conexao
        obj.preencheCombo(DDLCategoria, "Mul_Categoria", "cat_codigo", "cat_descricao", "", "cat_descricao")
    End Sub
End Class